package com.example.questionnaire.config;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

import java.util.Properties;


public class SSHConnection {

    // 需要了可以打开
    //本地测试的
//    private final static String S_PATH_FILE_PRIVATE_KEY = "c:/test/id_rsa";
    //2023.09.05 服务器上的
    private final static String S_PATH_FILE_PRIVATE_KEY = "/usr/data/app/ssh/id_rsa";



    // SSH远程服务器配置
    //https://h5.tcgoidc.com
    private final static String SSH_REMOTE_SERVER = "wx.tcgoidc.com";
    private final static int SSH_REMOTE_PORT = 22;
    private final static String SSH_USER = "hengri";
    private final static String SSH_PASSWORD = "";

    // 远程数据库配置
    private final static String MYSQL_REMOTE_SERVER = "wx.tcgoidc.com"; //""wx.tcgoidc.com";
    // 自定义的映射端口，需要和yml中的port保持一致
    private final static int LOCAl_PORT = 13307;

    private final static int REMOTE_PORT = 3306;

    private Session sesion; //represents each ssh session

    // 测试连接
    public static void main(String[] args) throws Throwable {
        System.out.println(new SSHConnection());
    }

    public SSHConnection() throws Throwable {

        System.out.println("SSHConnection--No运行");
        /*
        JSch jsch = new JSch();
        // 需要用到了开启
        // jsch.setKnownHosts(S_PATH_FILE_KNOWN_HOSTS);
        jsch.addIdentity(S_PATH_FILE_PRIVATE_KEY);
//        sesion = jsch.getSession(SSH_REMOTE_SERVER);
//        sesion.setPort(22);
//        sesion.setUserInfo();

        sesion = jsch.getSession(SSH_USER, SSH_REMOTE_SERVER, SSH_REMOTE_PORT);
//        sesion.setPassword(SSH_PASSWORD);

        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        sesion.setConfig(config);
        // 去连接
        sesion.connect(); //ssh connection established!
        //  设置转发
        sesion.setPortForwardingL(LOCAl_PORT, MYSQL_REMOTE_SERVER, REMOTE_PORT);

        System.out.println("SSHConnection--运行OK");

         */
    }

    public void closeSSH() {
//        sesion.disconnect();
    }
}

